#coding:utf-8
import talib
from py_at.strategy import Strategy
from py_at.Data import Data
from py_at.Bar import Bar
import numpy as np
import time
class HLcelue(Strategy):
    """军哥原来做的小高频"""
    def __init__(self,cfg):
        super().__init__(cfg)
        #初始化参数
        if cfg == "":
            return
        self.lots = self.Params['Lots']

    def OnBarUpdate(self, data=Data, bar=Bar):
        if len(self.C)<2:
            return

        if self.D[-1].split()[1]>='14:55:00' and self.D[-1].split()[1] <='15:00:00':
            if self.PositionShort>0:
                self.BuyToCover(self.O[-1],self.lots,'买平')

            return



        if self.PositionShort==0 and self.L[-1]<self.L[-2] and self.H[-2] != self.L[-2]:
            self.SellShort(min(self.O[-1], self.L[-2]), self.lots, '卖开')

        if self.PositionShort>0 and self.H[-1]>self.H[-2] and self.H[-2] != self.L[-2] and self.LastEntryDateShort!=self.D[-1]:
            print("平仓时间%s 平仓k开盘价%s  平仓前高%s 理论正确平仓价格%s" %(self.D[-1],self.O[-1],self.H[-2],max(self.O[-1],self.H[-2])))
            self.BuyToCover(max(self.O[-1],self.H[-2]), self.lots, '买平')







